<template>
  <div class="container">
    <!-- 公共头部 -->
    <van-nav-bar
      v-if="isShowNav"
      fixed
      title="黑马头条"
      right-text="搜索"
      @click-right="$router.push('/search')"
    />
    <!-- 渲染四个标签栏的二级路由 -->
    <div class="my-wrapper" :class="{ noTop: !isShowNav }">
      <!-- 缓存优化 -->
      <keep-alive include="home-index">
        <router-view />
      </keep-alive>
    </div>
    <!-- 公共标签栏 -->
    <van-tabbar route>
      <van-tabbar-item to="/" icon="home-o"> 首页 </van-tabbar-item>
      <van-tabbar-item to="/question" icon="chat-o"> 问答 </van-tabbar-item>
      <van-tabbar-item to="/video" icon="tv-o"> 视频 </van-tabbar-item>
      <van-tabbar-item to="/user" icon="user-o"> 我的 </van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  name: 'layout',
  computed: {
    isShowNav () {
      return this.$route.path !== '/user'
    }
  },
  created () {
    console.log('layout')
  }
}
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  position: relative;
  .my-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding-top: 46px;
    padding-bottom: 50px;
    box-sizing: border-box;
    &.noTop {
      padding-top: 0;
    }
  }
}
</style>
